/**
 * Created by yanghl on 2016/5/23.
 */

define(function (require, exports, module) {
  'use strict';

  var Constant = require("./constant");
  var Env = require("./env");
  /**
   * 工具类
   * @class common.CommonUtil
   */
  var CommonUtil = {};

  /**
   * 单位
   */
  CommonUtil.unit_100 = 100;
  /**
   * 显示小数点后几位
   * */
  CommonUtil.DECIMAL_PLACE = 2;

  /**
   * 显示小数点后几位
   * */
  CommonUtil.DECIMAL_PLACE_3 = 3;

  /**
   * 显示小数点后几位
   * */
  CommonUtil.DECIMAL_PLACE_0 = 0;


  /**
   * 判断是否为空
   * @method isEmpty
   * @param  val
   * @return {boolean}
   */
  CommonUtil.isEmpty = function (val) {
    return val === null || val === undefined || val === "" || val.length === 0;
  };

  /**
   *
   * @method isZeroOrEmpty
   * @param  val
   * @return {boolean}
   */
  CommonUtil.isZeroOrEmpty = function (val) {
    return val === null || val === undefined || val === "" || val.length === 0 || parseFloat(val) == 0;
  };
  /**
   * 工具类 获取url 参数
   * @method getUrlParam
   * @private
   */
  CommonUtil.getUrlParam = function (name, h) {
    var url = decodeURI(location.search); //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      var strs = str.split("&");
      for (var i = 0; i < strs.length; i++) {
        theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
      }
    }
    return theRequest[name];
  };

  /**
   * 判断是不是数字
   *
   * @static
   * @method isNumeric
   * @param  src
   * @return {boolean}
   */
  CommonUtil.isNumeric = function (src) {
    return $.isNumeric(src);
  };


  /**
   * 根据位数显示交易量(万)(亿)
   * 10200 => 102(手)
   * 1020000 => 1.02万(手)
   * 10200000000 => 1.02亿(手)
   *
   * @method addVolmeUnit
   * @param  val
   * @param  decimalPlace 保留几位小数
   * @returns {string}
   */
  CommonUtil.addFifthVolmeUnit = function (val) {
    var returnVal = "--";
    if (CommonUtil.isEmpty(val)) {
      return returnVal;
    }

    if (typeof val === "undefined" || CommonUtil.isEmpty(val)) {
      val = CommonUtil.unit_100;
    }

    var str = String(val);
    if (CommonUtil.isNumeric(str)) {
      var bigNumberVal = new BigNumber(val);
      bigNumberVal = bigNumberVal.dividedBy(new BigNumber(val));
      returnVal = CommonUtil.floor(bigNumberVal, 0);
    }
    return returnVal;
  };

  /**
   * 若大于或等于万为则转为几万
   * 例：9999  => 9999.00
   *    10000  => 1.00万
   *    12345  =>1.2345万
   */
  CommonUtil.addWangUnit = function (text) {
    if (isNaN(text)) {
      return text;
    }
    var num = Number(text).toFixed(2);
    if (num < 10000) {
      return num;
    }
    num = (Number(text) / 10000).toFixed(6);
    var strNum = num.toString();
    var len = strNum.length;
    var n = 0;
    for (var i = 1; i <= 4; i++) {
      if (strNum.charAt(len - i) == '0') {
        strNum = strNum.substring(0, strNum.length - 1);
      } else {
        break;
      }
    }
    return strNum + " 万";
  };
  /**
   * 判断正收益还是负收益
   * >=0 or String true
   * <0 false
   */
  CommonUtil.income = function (text) {
    if (isNaN(text)) {
      return true
    }
    text = Number(text);
    if (text >= 0) {
      return true;
    } else {
      return false;
    }
  };

  /**
   * 更新样式  为红色 -为绿色
   *
   * @method
   * @param  $el
   * @param  val
   * @param  [option={}]
   * @param  [option._raw]
   * @static
   */
  CommonUtil.updateArryRatioStyle = function (prentPrice, prevClose) {
    if (CommonUtil.isNumeric(prentPrice) && CommonUtil.isNumeric(prevClose)) {
      var comp = new BigNumber(prentPrice).comparedTo(new BigNumber(prevClose));
      var klass = (comp > 0) ? "color-red" : ((comp < 0) ? "color-green" : undefined);
      return klass;
    }
    return "";
  };
  /**
   * 小数点第３位以(DECIMAL_PLACE = 2)
   *
   * @method floor
   * @param  text
   * @param  [decimalPlace=DECIMAL_PLACE]
   * @return {string}
   * @static
   */
  CommonUtil.floor = function (text, decimalPlace) {
    if (typeof decimalPlace === "undefined") {
      decimalPlace = CommonUtil.DECIMAL_PLACE;
    }
    if (CommonUtil.isNumeric(text)) {
      return new BigNumber(text).round(decimalPlace, BigNumber.ROUND_DOWN).toFixed(decimalPlace);
    } else {
      return text;
    }
  };

  /**
   * 小数点第３位以(DECIMAL_PLACE = 2)
   *
   * @method floor
   * @param  text
   * @param  [decimalPlace=DECIMAL_PLACE]
   * @return {string}
   * @static
   */
  CommonUtil.floor3 = function (text, decimalPlace) {
    if (typeof decimalPlace === "undefined") {
      decimalPlace = CommonUtil.DECIMAL_PLACE;
    }
    if (CommonUtil.isNumeric(text)) {
      return new BigNumber(text).round(decimalPlace, BigNumber.ROUND_HALF_UP).toFixed(decimalPlace);
    } else {
      return text;
    }
  };

  /**
   * 最多保留decimalPlace位小数，
   * 若实际小数位数<decimalPlace,则不变。
   * @method floor
   * @param  text
   * @param  [decimalPlace=DECIMAL_PLACE]
   * @return {string}
   * @static
   */
  CommonUtil.floorMax6 = function (text, decimalPlace) {
    if (isNaN(text)) {
      return text;
    }
    if (text.toString().split(".")[1].length > 6) {
      text = Number(text).toFixed(6)
    } else {
      return Number(text);
    }
  };

  /**
   * 买卖数量必须是100的整数倍，四舍五入：买入时零数大于等于50股进1位，小于50股则舍去零数。
   * @method floor
   * @param  text
   * @return int
   * @static
   */
  CommonUtil.floor100 = function (text) {
    if (isNaN(text)) {
      return text;
    } else {
      text = Number(text)
    }
    text = text - text % 100;
    return text
  };


  /**
   * 判断百分百是否为负数
   * @param str
   * @returns {boolean}
   */
  CommonUtil.upPercentStyle = function (str) {
    var reg = /^\-\d+\.?\d+%$/;
    var reg1 = /^\-\d+\.?\d+%$/;
    var isDown = reg.test(str);
    if (isDown) {
      return "value-down";
    } else if (parseFloat(str) != 0) {
      return "value-up";
    }
  };

  /**
   * 数字每3位加一个逗号
   * @param str
   * @returns {String}
   */
  CommonUtil.addCommas = function (nStr) {
    nStr += '';
    var x = nStr.split('.');
    var x1 = x[0];
    var x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
      x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
  };

  /**
   * 判断市场，由标志获取字段值
   */
  CommonUtil.getExchangeType = function (stockCode) {
    if (stockCode.substring(0, 2) == "SH") {
      return "1";
    } else if (stockCode.substring(0, 2) == "SZ") {
      return "0";
    }
  };

  /**
   * 判断市场，由字段值获取标志
   */
  CommonUtil.getMarketCode = function (exchangeType) {
    if (typeof exchangeType === "undefined") {
      return "";
    }
    if (exchangeType == "SH") {
      return "SH";
    } else if (exchangeType == "SZ") {
      return "SZ";
    } else if (exchangeType == 1) {
      return "SH";
    } else {
      return "SZ";
    }
  };

  /**
   * 获取当前日期
   * yyyyMMdd
   */
  CommonUtil.getTodayFormatDate = function () {
    var date = new Date();
    var seperator1 = "";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    return currentdate;
  };

  /**
   * 获取当前时分秒，补0
   * HHmmss
   */
  CommonUtil.getTodayFormatTime = function () {
    var date = new Date();

    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();

    if (hour < 10) {
      hour = "0" + hour;
    }

    if (minute < 10) {
      minute = "0" + minute;
    }

    if (second < 10) {
      second = "0" + second;
    }

    var currentTime = hour + "" + minute + "" + second;
    return currentTime;
  };

  /**
   * 获取当前时间
   * yyMMddhhmm 或yyMdhm、yyMddhhmm ...不补0
   */
  CommonUtil.getNowTime = function () {
    var date = new Date();
    var year = (date.getFullYear() + "").substring(2, 4);
    var month = date.getMonth() + 1;
    if (month == 10) {
      month = 'A'
    } else if (month == 11) {
      month = 'B'
    } else if (month == 12) {
      month = 'C'
    } else {
      month = month + "";
    }
    var day = date.getDate() + "";
    var hour = date.getHours() + "";
    var minute = date.getMinutes() + "";
    var second = date.getSeconds() + "";
    var currentdate = year + month + day + hour + minute + second;
    return currentdate;
  };

  /**
   * 四舍五入
   * @param number 需要处理的数字
   * @param digits 小数位数
   */
  CommonUtil.toFixed = function (number, digits) {
    if (number === "") {
      return "";
    }
    if (isNaN(number)) {
      return number;
    }
    var object = new Number(number);
    var result = object.toFixed(digits);

    if (result == "-0.00") { // 解决部分负数保留两位小数后，-0.00，0.00 页面样式不一致问题，如 -0.0000012
      result = "0.00";
    }

    return result;
  };

  /**
   * 时间格式化
   * new date() >> yyyy-MM-dd hh:mm:ss
   */
  CommonUtil.formatDateTime = function (strTime) {
    if (typeof strTime === "undefined") {
      var date = new Date();
    } else {
      var date = new Date(strTime);
    }
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    if (Number(month) < 10) {
      month = "0" + month.toString()
    }
    if (Number(day) < 10) {
      day = "0" + day.toString()
    }
    if (Number(hour) < 10) {
      hour = "0" + hour.toString()
    }
    if (Number(minute) < 10) {
      minute = "0" + minute.toString()
    }
    if (Number(second) < 10) {
      second = "0" + second.toString()
    }
    return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
  };

  /**
   * 当前日期格式化
   * newDate >> yyyyMMdd
   */
  CommonUtil.formatNowDate = function (strDate) {
    if (typeof strDate === "undefined") {
      var date = new Date();
    } else {
      var date = new Date(strDate);
    }
    var month = date.getMonth() + 1;
    var day = date.getDate();
    month = month < 10 ? ("0" + month) : ("" + month);
    day = day < 10 ? ("0" + day) : ("" + day);
    return Number(date.getFullYear() + "" + month + day);
  };

  /**
   * 日期格式化
   * yyyyMMdd >> yyyy-MM-dd
   */
  CommonUtil.formatDate = function (strDate) {
    strDate = strDate + "";
    if (!isNaN(strDate) && strDate.length == 8) {
      strDate = strDate.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1-$2-$3");
    }
    return strDate;
  };

  /**
   * 日期格式化
   * yyyyMMdd >> yyyy/MM/dd
   */
  CommonUtil.formatDateSlash = function (strDate) {
    strDate = strDate + "";
    if (!isNaN(strDate) && strDate.length == 8) {
      strDate = strDate.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1/$2/$3");
    }
    return strDate;
  };

  /**
   * 日期格式化
   * yyyyMMdd >> yyyy.MM.dd
   */
  CommonUtil.formatDatePoint = function (strDate) {
    strDate = strDate + "";
    if (!isNaN(strDate) && strDate.length == 8) {
      strDate = strDate.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1.$2.$3");
    }
    return strDate;
  };

  /**
   * 时间格式化
   * hhmmss >> hh:mm:ss
   */
  CommonUtil.formatTime = function (time) {
    time = time + "";
    if(isNaN(time) || time.indexOf(".") > 0 || time<0){
      return time;
    }
    if (time.length == 5) {
      time = "0" + time;
    } else if (time.length == 4) {
      time = "00" + time;
    } else if (time.length == 3) {
      time = "000" + time;
    } else if (time.length == 2) {
      time = "0000" + time;
    } else if (time.length == 1) {
      time = "00000" + time;
    }
    if (time.length == 6) {
      time = time.replace(/^(\d{2})(\d{2})(\d{2})$/, "$1:$2:$3");
    }
    return time;
  };

  /**
   * 时分格式化
   * hhmmss 或 hmmss >> hh:mm
   */
  CommonUtil.formatHourMinute = function (time) {
    time = time + "";
    if(isNaN(time) || time.indexOf(".") > 0 || time<0){
      return time;
    }
    if (time.length == 5) {
      time = "0" + time;
    } else if (time.length == 4) {
      time = "00" + time;
    } else if (time.length == 3) {
      time = "000" + time;
    } else if (time.length == 2) {
      time = "0000" + time;
    } else if (time.length == 1) {
      time = "00000" + time;
    }
    if (time.length == 6) {
      time = time.replace(/^(\d{2})(\d{2})(\d{2})$/, "$1:$2");
    }
    return time;
  };

  /**
   * 当前时分格式化
   * new Date() >> hh:mm
   */
  CommonUtil.formatNewHMTime = function () {
    var now = new Date();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    if (hours < 10) {
      hours = "0" + hours;
    }
    if (minutes < 10) {
      minutes = "0" + minutes;
    }
    var timeStr = hours + ":" + minutes;
    return timeStr;
  };

  /**
   * 计算两个日期间隔天数
   * @param startTime 开始日期（毫秒）
   * @param endTime 结束日期（毫秒）
   * */
  CommonUtil.dateDiff = function (startTime, endTime) {
    // var startTime = new Date(Date.parse(startDate.replace(/-/g, "/"))).getTime();
    // var endTime = new Date(Date.parse(endDate.replace(/-/g,   "/"))).getTime();
    var dates = (startTime - endTime) / (1000 * 60 * 60 * 24);
    return dates;
  };

  /**
   * 获取 endDate的前days天的日期
   * @param endDate   Date
   * @param days      int
   * @return {string}
   */
  CommonUtil.getStartDate = function (endDate, days) {
    var day = endDate.getDate();
    var endDateTime = endDate.getTime();
    var startDateTime = endDateTime - days * 24 * 60 * 60 * 1000;
    var startDate = new Date(startDateTime);
    var tempMonth = startDate.getMonth() + 1;
    tempMonth = tempMonth < 10 ? '0' + tempMonth : tempMonth;
    var tempDay = startDate.getDate();
    tempDay = tempDay < 10 ? '0' + tempDay : tempDay;
    return startDate.getFullYear() + '' + tempMonth + '' + tempDay;
  };

  /**
   * 获取 当下到截止时间的时间距离
   * @param time   截止时间，yyyyMMdd
   * @return {string}
   */
  CommonUtil.countdownTime = function (time) {
    var endTime = new Date(CommonUtil.formatDate(time));
    var nowTime = new Date();
    var closing_stamp = endTime.getTime() - nowTime.getTime();
    var days = parseInt(closing_stamp / 86400000);
    var hours = nowTime.getHours();
    var min = nowTime.getMinutes();
    var sec = nowTime.getSeconds();
    if (hours < 10) {
      hours = "0" + hours;
    }
    if (min < 10) {
      min = ":0" + min;
    } else {
      min = ":" + min;
    }
    if (sec < 10) {
      sec = ":0" + sec;
    } else {
      sec = ":" + sec;
    }
    if (days > 1 || days == 1) {//剩余大于1天
      return days + "天" + hours + min + sec;
    } else {//剩余小于1天
      return "" + hours + min + sec;
    }
  };

  /**
   * 判断设备,返回'IOS'或’'Android'
   * return String
   */
  CommonUtil.Equ = function () {
    var u = navigator.userAgent;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
    if (isAndroid) {
      return "Android";
    } else if (isIOS) {
      return "IOS";
    }
    return "";
  };
  /**
   * 根据市场返回交易类型
   *  @param tradeType   交易类型 buy 买入 sell 卖出
   *  @param marketCd   市场 0深圳 1上海
   */
  CommonUtil.getTradeTypes = function (tradeType, marketCd) {
    var list = [];
    //没选则股票只展示现价委托
    if (CommonUtil.isEmpty(marketCd)) {
      var key = tradeType == "sell" ? "0" : "1";
      list.push({value: key, text: "限价委托", showText: "限价委托"});
    } else {
      var key = tradeType == "sell" ? "0" : "1";
      list.push({value: key, text: "限价委托", showText: "限价委托"});
      var key1 = tradeType == "sell" ? "8" : "7";
      var obj1 = {value: key1, text: "市价委托（五档成交剩余撤销）", showText: "五档成交剩余撤销"};

      if (marketCd == "0") {
        var key2 = tradeType == "sell" ? "12" : "11";
        var obj2 = {value: key2, text: "市价委托（对手方最优）", showText: "对手方最优"};

        var key3 = tradeType == "sell" ? "14" : "13";
        var obj3 = {value: key3, text: "市价委托（本方最优）", showText: "本方最优"};

        var key4 = tradeType == "sell" ? "16" : "15";
        var obj4 = {value: key4, text: "市价委托（即时成交剩余撤销）", showText: "即时成交剩余撤销"};

        var key5 = tradeType == "sell" ? "18" : "17";
        var obj5 = {value: key5, text: "市价委托（全额成交或撤销）", showText: "全额成交或撤销"};
        list.push(obj2);
        list.push(obj3);
        list.push(obj4);
        list.push(obj1);
        list.push(obj5);
      } else {
        var key2 = tradeType == "sell" ? "10" : "9";
        var obj2 = {value: key2, text: "市价委托（五档成交剩余转限）", showText: "五档成交剩余转限"};
        list.push(obj1);
        list.push(obj2);

      }
    }
    return list;
  };
  /**
   * 根据买卖类型 返回买、卖
   *  @param tradeType
   */
  CommonUtil.getBuyOrSellBuyType = function (tradeType) {
    if (tradeType == "1" || tradeType == "7" || tradeType == "9" ||
      tradeType == "11" || tradeType == "13" || tradeType == "15" ||
      tradeType == "17") {
      return "1";
    } else if (tradeType == "0" || tradeType == "8" || tradeType == "10" || tradeType == "12" ||
      tradeType == "14" || tradeType == "16" || tradeType == "18") {
      return "0";
    }
    return "";
  };
  /**
   * 格式化时间
   * 20000909 --> 2000-09-09
   */
  CommonUtil.dateFormat = function (date) {
    if (CommonUtil.isEmpty(date)) {
      return "";
    }
    date = date + "";
    if (date.length != 8) {
      return date;
    }
    return date.substr(0, 4) + "-" + date.substr(4, 2) + "-" + date.substr(6, 2);
  };

  /**
   *往本地存储token
   *要是header中有token，存入本地
   * @param  data 返回的请求头
   */
  CommonUtil.saveyyzToken = function (data) {
    // console.log("gmas_token" in data);
    if ("gmas_token" in data) {
      localStorage.setItem(Constant.YYZ_TOKEN, data.gmas_token);
    }
  };

  /**
   *如果本地缓存中有token，就放入传送的参数中
   * @param param
   */
  CommonUtil.setToken = function (param) {
    var token = localStorage.getItem(Constant.YYZ_TOKEN);
    if (token !== "" && token !== null) {
      param.gmas_token = token;
    }
    //console.log(param);
    return param;
  };

  /**
   *处理金策略的游客身份也可以查看的接口
   * 30012,30016,30008,30006,30010,30014,30026
   * @param param
   * @param bridgeParam
   */
  CommonUtil.setTouristParam = function (param, bridgeParam) {
    var nickname = localStorage.getItem(Constant.storage.NICKNAME);
    var usercode = localStorage.getItem(Constant.storage.USER_CODE);
    if (nickname === "" || nickname === null || nickname === undefined) {
      //游客状态
      bridgeParam.param = param;
      bridgeParam.touristParameter = {
        "mobile": "phone_no",
        "password": "stock_pwd",
        "user_code": "user_code"
      };
    } else {
      //登录状态
      param.user_code = usercode;
      //param.client_id = usercode;
      bridgeParam.param = param;
      bridgeParam.localParameter = {"mobile": "phone_no", "password": "stock_pwd"};
    }
    return bridgeParam;
  };

  /**
   *处理用户中心的游客身份也可以查看的接口
   * 12008301,12008302,12008305,12008310,12008312,12008315,12008316
   * @param param
   * @param bridgeParam
   */
  CommonUtil.setUsercenterTouristParam = function (param, bridgeParam) {
    var nickname = localStorage.getItem(Constant.storage.NICKNAME);
    var usercode = localStorage.getItem(Constant.storage.USER_CODE);
    if (nickname === "" || nickname === null || nickname === undefined) {
      //游客状态
      bridgeParam.param = param;
      bridgeParam.touristParameter = {"mobile": "phone_no", "password": "stock_pwd", "user_code": "user_code"};
    } else {
      //登录状态
      param.user_code = usercode;
      bridgeParam.param = param;
      bridgeParam.localParameter = {"mobile": "phone_no", "password": "stock_pwd"};
    }
    return bridgeParam;
  };

  /**
   * 获取设备点击事件名称。
   *
   * @method tapType
   * @return string
   */
  CommonUtil.tapType = function () {

    var type = "click";
    if (Env.isAndroid() || Env.isIOS()) {
      type = "tap";
    }
    return type;
  };

  /**
   * 获取默认头像
   * @param bridgeParam
   */
  CommonUtil.getDefaultUserHead = function (userCode) {
    if(userCode){
      var defaultHeaderIndex = userCode % 8 + 1;
      return 'https://dl.app.gtja.com/pictures/niutou/tou' + defaultHeaderIndex + '@2x.png';
    }else{
      return require('../assets/images/tou1@2x.png');
    }
  };

  /**
   * 当前时间是否为评论时间端
   * @param time
   */
  CommonUtil.isCommentTime = function (time) {
    time = time + "";
    if (time.length == 5) time = '0' + time;
    if (Constant.game.COMMENT_TIME.am.start <= time && time <= Constant.game.COMMENT_TIME.am.end) {
      return true;
    } else if (Constant.game.COMMENT_TIME.pm.start <= time && time <= Constant.game.COMMENT_TIME.pm.end) {
      return true;
    } else {
      return false;
    }

  };

  /**
   * 获取可评论时间
   *[
   {
       b: '09:00:00',
       e: '12:00:00'
   },
   {
       b: '13:00:00',
       e: '17:00:00'
   }
   ]
   */
  CommonUtil.getTalkTime = function (cb) {
    $.ajax({
      type: 'GET',
      url: "https://dl.app.gtja.com/nrng/task/talkTime.json",
      dataType: "jsonp",
      jsonp: "callback",
      jsonpCallback: 'talkTime',
      success: function (response) {
        // body...
        if (response.length > 0) {
          cb(response);
        }
      }
    });
    
  };

  /**
   * 取调仓原因信息
   * @param reason
   * @returns {*}
   */
  CommonUtil.getReasonOption = function (reason) {
    var obj = {};
    if(_.isEmpty(reason) || reason.indexOf("|") == -1){
      return null;
    }
    var tempArray = reason.split("|");
    //如果没取到原因对应的icon默认取第一个
    obj.reasonIcon = Constant.REASON_ICON[tempArray[0]] ? Constant.REASON_ICON[tempArray[0]] : Constant.REASON_ICON["1"];
    obj.reasonText = tempArray.length == 2 ? tempArray[1] : "" ;
    return obj;
  };

  /**
   * 判断字符串占用了多少字节
   * @param str
   */
  CommonUtil.sizeOfStr = function (str) {
    return str.replace(/[^\x00-\xff]/g, 'xx').length;
  };

  /**
   * 生产基金状态转模拟基金状态
   * @param Array
   * @return Array
   */
  CommonUtil.translateFundsStatus = function (list) {
    for (var i=0;i<list.length;i++){
      switch (list[i].fundStatus.toString()){
        case '0':list[i].statusName = "可申购赎回";break;
        case '1':list[i].statusName = "发行";break;
        case '2':list[i].statusName = "其他";break;
        case '3':list[i].statusName = "其他";break;
        case '4':list[i].statusName = "停止申购赎回";break;
        case '5':list[i].statusName = "停止申购";break;
        case '6':list[i].statusName = "停止赎回";break;
        case '7':list[i].statusName = "其他";break;
        case '8':list[i].statusName = "其他";break;
        case '9':list[i].statusName = "基金封闭";break;
        case 'a':list[i].statusName = "基金终止";break;
        default:list[i].statusName = "";break
      }
    }
    return list
  };

  /**
   * 模拟基金状态转换(认购、申购、赎回)
   * @param ofstatue
   */
  CommonUtil.getStatusName = function (ofstatue) {
    var statusName = "";
    switch(String(ofstatue)){
      case "0" : statusName = "可申购赎回"; break;
      case "1" : statusName = "发行"; break;
      case "4" : statusName = "停止申购赎回"; break;
      case "5" : statusName = "停止申购"; break;
      case "6" : statusName = "停止赎回"; break;
      case "8" : statusName = "基金终止"; break;
      case "9" : statusName = "基金封闭"; break;
      default  : statusName = "其他"; break;
    }
    return statusName;
  };


  return CommonUtil;
});
